package com.goods.business.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.goods.business.mapper.InStockMapper;
import com.goods.business.service.InStockService;
import com.goods.common.model.business.InStock;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class InStockServiceImpl implements InStockService {

    @Autowired
    private InStockMapper inStockMapper;

    //入库单（入库记录）数据分页列表展示
    @Override
    public PageVO<InStockVO> findInStockList(Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        List<InStockVO> inStockVOS = inStockMapper.selectAll().stream().map(inStock -> {
            InStockVO inStockVO = new InStockVO();
            BeanUtils.copyProperties(inStock,inStockVO);
            inStockVO.setCreateTime(new Date());
            inStockVO.setModified(new Date());
            return inStockVO;
        }).collect(Collectors.toList());
        PageInfo<InStockVO> info = new PageInfo<>(inStockVOS);
        return new PageVO<>(info.getTotal(),inStockVOS);
    }
}
